<%--
  Created by IntelliJ IDEA.
  User: Mr.G
  Date: 2019/1/23
  Time: 19:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>详情页面</title>
</head>
<style>
    #huiyuanka{
        display: none;

    }
    #xianjin{
        display: none;
    }
</style>
<body>
<form class="layui-form"  lay-filter="zhifu" id="zhifu" action="">
    <%--会员卡号--%>
        <input type="hidden" name="payId">
    <table class="layui-table">
        <tr>
            <td>病历号:</td>
            <td><input type="text" class="layui-input" name="memberCaseNo" id="caseNo"></td>
            <td>患者姓名:</td>
            <td><input type="text" class="layui-input" name="memberCaseName"></td>

        </tr>
        <tr>
            <td>主治医生:</td>
            <td><input type="text" class="layui-input" name="userName"></td>
            <td>支付方式：</td>
            <td><input type="text" class="layui-input" name="moneyType"></td>
        </tr>
        <tr>
            <td>总金额：</td>
            <%--<td><input type="text" id="zongjine" class="layui-input"></td>--%>
            <td><span class="zongjine"></span></td>
            <td>会员卡号：</td>
            <td>
                <input type="text" class="layui-input" readonly name="memberId" id="memberId">
            </td>
        </tr>
        <tr id="huiyuanka">
            <td>会员卡余额：</td>
            <td><span class="huiyuankayue"></span></td>
        </tr>
        <tr id="xianjin">
            <td>应收金额：<span class="zongjine"></span></td>
            <td>找零：<span class="zhaoling">-</span></td>
            <td>实收金额：</td>
            <td><input type="text" class="layui-input" id="shishoujine"></td>
        </tr>

        <tr>
            <table id="mingxi" name="mingxi" lay-filter="mingxi"></table>
            <input type="hidden" name="zhiliaoxiangmu" id="zhiliaoxiangmu">
        </tr>
    </table>
        <table class="layui-table">
            <tr>
                <td>备注：</td>
                <td><textarea id="demo" class="layui-textarea" name="remark"></textarea></td>
            </tr>
        </table>


    <script>

        //富文本编辑器组件
        var layedit = layui.layedit;
        layedit.build('demo'); //建立编辑器
        layedit.build('demo', {
            height: 100 //设置编辑器高度
        });

        $("#shishoujine").on("keyup", function (e) {
            var shishou = $("#shishoujine").val();
            if (shishou == ''){
                $(".zhaoling").html("-")
                return
            }

            var yingshou = $(".zongjine:eq(0)").text();
            console.log(yingshou)
            $(".zhaoling").html(shishou - yingshou)
        });


            layui.form.render()
            var zhiliaojine = 0;
            setTimeout(function () {
                var caseNo = $("#caseNo").val();
                $.get("${path}/patment/getPayId",{caseNo:caseNo,pstate:1},function (payId) {
                    $.get("${path}/patment/getgetPatmentInfo",{payId:payId},function (PatmentInfoList) {
                        layui.table.render({
                            elem: '#mingxi'
                            ,id:'mingxi'
                            ,url: '' //数据接口
                            ,data:PatmentInfoList
                            ,page: true //开启分页
                            ,cols: [[ //表头
                                {field: 'option', title: '治疗项目'},
                                {field: 'number', title: '数量'},
                                {field: 'money', title: '价格'}
                            ]],
                            done: function(res, curr, count){
                                zhiliaojine = 0;
                                //如果是异步请求数据方式，res即为你接口返回的信息。
                                // 如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                                //res.data 表格中所有的数据
                                console.log(res.data);

                                $.each(res.data,function () {
                                    zhiliaojine += this.money;
                                })

                                $(".zongjine").html(zhiliaojine)
                                console.log("治疗金额为："+zhiliaojine)
                            }
                        })
                    })
                })

            },300)

                //监听select下拉框事件
            layui.form.on('select(moneyType)', function(data){
                // console.log(data.value); //得到被选中的值
                // $("#moneyType").val(data.value)
                var type = data.value;
                if (type == "会员卡"){

                    var menberId = $("#memberId").val();
                    $("#huiyuanka").show()
                    $("#xianjin").hide();


                    $.get("${path}/patment/getyue",{menberId:menberId},function (data) {
                        $(".huiyuankayue").html(data)
                    })

                }else if  (type == "现金"){
                    $("#xianjin").show();
                    $("#huiyuanka").hide()
                }

            })

    </script>


</form>
</body>
</html>
